//
//  MineAlterInfoTableCell.m
//  ArtDog
//
//  Created by dllo on 16/8/30.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "MineAlterInfoTableCell.h"
#import "MineHomepageModel.h"
#import "UIImageView+WebCache.h"
#import "UIColor+Common.h"

@interface MineAlterInfoTableCell ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UIButton *manBtn;
@property (weak, nonatomic) IBOutlet UIButton *womanBtn;

@property (weak, nonatomic) IBOutlet UIImageView *headPicImage;

@property (weak, nonatomic) IBOutlet UITextField *usernameText;
@property (weak, nonatomic) IBOutlet UIImageView *manImageView;

@property (weak, nonatomic) IBOutlet UIImageView *womanImageView;

@property (weak, nonatomic) IBOutlet UITextView *introduceText;

@property (weak, nonatomic) IBOutlet UILabel *placeholderLabel;

@property (weak, nonatomic) IBOutlet UILabel *workCountLabel;

@end

@implementation MineAlterInfoTableCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.contentView layoutIfNeeded];
    
    _manImageView.layer.borderWidth = 2;
    
    _womanImageView.layer.borderWidth = 2;
    
    _introduceText.delegate = self;
    self.selected = NO;
    
   
}

- (void)textViewDidChange:(UITextView *)textView
{
    if (textView.text.length == 0) {
        _placeholderLabel.hidden = NO;
    } else {
        _placeholderLabel.hidden = YES;
    }
    _workCountLabel.text = [NSString stringWithFormat:@"%ld/40", (unsigned long)textView.text.length];
}

- (IBAction)manAction:(id)sender {
    _womanImageView.image = [UIImage imageNamed:@"noselected"];
    _womanImageView.layer.borderColor = [UIColor colorFromHexRGB:@"8a8a8a"].CGColor;
    _manImageView.image = [UIImage imageNamed:@"icon_readed"];
    _manImageView.layer.borderColor = [UIColor blackColor].CGColor;
    [(UIButton *)sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_womanBtn setTitleColor:[UIColor colorFromHexRGB:@"8a8a8a"] forState:UIControlStateNormal];
}

- (IBAction)womanAction:(id)sender {
    _manImageView.image = [UIImage imageNamed:@"noselected"];
    _manImageView.layer.borderColor = [UIColor colorFromHexRGB:@"8a8a8a"].CGColor;
    _womanImageView.image = [UIImage imageNamed:@"icon_readed"];
    _womanImageView.layer.borderColor = [UIColor blackColor].CGColor;
    [(UIButton *)sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_manBtn setTitleColor:[UIColor colorFromHexRGB:@"8a8a8a"] forState:UIControlStateNormal];
}

- (IBAction)saveAction:(id)sender {
}


- (void)setModel:(MineHomepageModel *)model
{
    _model = model;
    [_headPicImage sd_setImageWithURL:[NSURL URLWithString:model.headPic] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    _usernameText.text = model.userName;
    if ([model.sex integerValue] == 1) {
        _womanImageView.image = [UIImage imageNamed:@"noselected"];
        _womanImageView.layer.borderColor = [UIColor colorFromHexRGB:@"8a8a8a"].CGColor;
        [_womanBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_manBtn setTitleColor:[UIColor colorFromHexRGB:@"8a8a8a"] forState:UIControlStateNormal];
        _manImageView.image = [UIImage imageNamed:@"icon_readed"];
        _manImageView.layer.borderColor = [UIColor blackColor].CGColor;
    } else {
        _manImageView.image = [UIImage imageNamed:@"noselected"];
        _manImageView.layer.borderColor = [UIColor colorFromHexRGB:@"8a8a8a"].CGColor;
        _womanImageView.image = [UIImage imageNamed:@"icon_readed"];
        _womanImageView.layer.borderColor = [UIColor blackColor].CGColor;
        [_manBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_womanBtn setTitleColor:[UIColor colorFromHexRGB:@"8a8a8a"] forState:UIControlStateNormal];
    }
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [self.contentView layoutIfNeeded];
    _womanImageView.layer.cornerRadius = CGRectGetWidth(_manImageView.frame) / 2;
    _manImageView.layer.cornerRadius = CGRectGetWidth(_manImageView.frame) / 2;
    _headPicImage.layer.cornerRadius = CGRectGetWidth(self.contentView.frame) / 6;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
